package com.device.controller;

import com.device.annotation.LoginUser;
import com.device.dataobject.ro.*;
import com.device.dataobject.vo.ResultVO;
import com.device.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;
    @Autowired
    public UserController(UserService userService) {

        this.userService = userService;
    }


    @GetMapping("/{id}")
    public ResultVO findById(@PathVariable("id") Integer id) {

        return userService.findById(id);
    }

    @RequestMapping(value = "/avatar", method = RequestMethod.POST)
    public ResultVO uploadAvatar(@LoginUser Integer userId, MultipartFile file) {
        return userService.uploadAvatar(userId, file);
    }

    @RequestMapping(value = "/poster", method = RequestMethod.POST)
    public ResultVO uploadPoster(@LoginUser Integer userId, MultipartFile file) {
        return userService.uploadPoster(userId, file);
    }


    @PostMapping
    public ResultVO create(@RequestBody WxUserInfoRO userRO) {
       return userService.create(userRO);
    }

    @PutMapping
    public ResultVO update(@LoginUser Integer userId, @RequestBody UpdateDef[] opArray) {
       return userService.update(userId, opArray);
    }


    @GetMapping("/rent")
    public ResultVO getUserRent(@LoginUser Integer userId, Integer page , Integer size) {
        return userService.getUserRent(userId, page, size);
    }

    @GetMapping("/rent/{id}")
    public ResultVO getRentDetail(@LoginUser Integer userId ,@PathVariable("id") Integer id) {
        return userService.getRentDetail(userId, id);
    }

    @DeleteMapping("/rent/{id}")
    public ResultVO deleteRent(@LoginUser Integer userId, @PathVariable("id") Integer id) {
       return userService.deleteRent(userId, id);
    }

    @GetMapping("/post")
    public ResultVO getUserPost(@LoginUser Integer userId, Integer page , Integer size) {
        return userService.getUserPost(userId, page, size);
    }

    @GetMapping("/post/{id}")
    public ResultVO getPostDetail(@LoginUser Integer userId ,@PathVariable("id") Integer id) {
        return userService.getPostDetail(userId, id);
    }
    @DeleteMapping("/post/{id}")
    public ResultVO deletePost(@LoginUser Integer userId, @PathVariable("id") Integer id) {
        return userService.deletePost(userId, id);
    }
    @PostMapping("/post")
    public ResultVO Post(@LoginUser Integer userId,@RequestBody PostRO postRO) {
        return userService.post(userId, postRO);
    }
    @PostMapping("/rent")
    public ResultVO Rent(@LoginUser Integer userId, @RequestBody RentRO rentRO) {
        return userService.rent(userId, rentRO);
    }

    @PostMapping("/login")
    public ResultVO login(@RequestBody LoginRO loginRO) {

        return userService.login(loginRO);
    }

    @PostMapping("/register")
    public ResultVO register(@LoginUser Integer userId, @RequestBody RegisterRO registerRO) {
        return userService.register(userId, registerRO);
    }

}








